
# 协程实现计算平均数
def coro_averange():
    total = 0
    length = 0
    while True:
        try:
            result = yield total/length
        except ZeroDivisionError:
            result = yield 0
        total += result
        length += 1

my_avg = coro_averange()
print(f"初始化：{next(my_avg)}")
while True:
    temp = int(input("请输入一个数字："))
    print(f"此时已输入值的平均数为：{my_avg.send(temp)}")


#编写一个asyncio异步程序
import asyncio

async def count(index) :
    print(f"first counting_{index}")
    await asyncio.sleep(1)
    print(f"second counting_{index}")

loop = asyncio.get_event_loop()
task_array = []
for i in range(5):
    task_array.append(count(i))
loop.run_until_complete(asyncio.wait(task_array))
loop.close()
